//移入移出
require(["../../static/conf/config.js"], function () {
    require(["jquery"], function ($) {
        let $city = $(".current-city")
        let $cityList = $(".current-city-list")
        let $message = $(".header-message")
        let $messageList = $(".message-list-header")
        let $applist = $("#app-list")
        let $APP = $("#APP")
        let $weixin = $(".footer-weixin")
        let $weixinErweima = $(".footer-weixin-erweima")
        let $footApp = $(".footer-app")
        let $appErweima = $(".footer-app-erweima")
        let $headerUser = $(".header-user")
        let $HeaderUser = $("#header-user")
        $headerUser.mouseenter(function() {
            $HeaderUser.show("slow");
        })
        $HeaderUser.mouseleave(function(){
            $HeaderUser.hide();
        })
        $weixin.mouseenter(function() {
            $weixinErweima.show("slow");
        })
        $weixin.mouseleave(function(){
            $weixinErweima.hide();
        })
        $footApp.mouseenter(function() {
            $appErweima.show("slow");
        })
        $footApp.mouseleave(function(){
            $appErweima.hide();
        })
        $APP.mouseenter(function() {
            $applist.show("slow");
        })
        $applist.mouseleave(function(){
            $applist.hide();
        })
        $city.mouseenter(function() {
            $cityList.show("slow");
        })
        $cityList.mouseleave(function(){
            $cityList.hide();
        })
        $message.mouseenter(function() {
            $messageList.show("slow");
        })
        $messageList.mouseleave(function(){
            $messageList.hide();
        })
    })
})

//登录状态的检测和退出登录
require(["../../static/conf/config.js"], function () {
    require(["jquery"], function ($) {
        $(document).ready(function () {

            let obj = localStorage.getItem('logined');
            if (obj !== null) {
                $(".logined").show()
                $(".not-login").hide()
            }
            if (obj == null) {
                $(".logined").hide()
                $(".not-login").show()
            }

            $(".quit").click(function () {
                localStorage.removeItem("logined")
                $(".logined").hide()
                $(".not-login").show()
            })

        })

    })
})


require(["../../static/conf/config.js"], function () {
    require(["jquery"], function ($) {
        $(".cat-list").children("dd").click(function () {
            $(this).addClass("active").siblings().removeClass("active")
        })
        $(".tag-list").children("dd").click(function () {
            $(this).addClass("active").siblings().removeClass("active")
        })

        $("pro-list-su").children("a").click(function(){
            alert("333")
            $(".pro-specifications").css({  
                display : "block"
            });
        })

        
    })
})

//ajax
let product = document.getElementById("view");
let xhr = new XMLHttpRequest();
xhr.open("get", "http://localhost:9090/product")
xhr.onload = function () {
    let module = JSON.parse(xhr.response);
    product.innerHTML = template("modules", module);
    console.log(module.data.goodsArr[1].goods)
}
xhr.send();

//模板引擎
function template(id, module) {
    let template = document.getElementById(id).innerHTML;
    template = 'print(`' + template + '`)';
    template = template.replace(/<%=(.+?)%>/g, '`) \n print( $1 ) \n print(`');
    template = template.replace(/<%(.+?)%>/g, '`) \n $1 \n print(`');

    var codestr = `
    (function(data) {
        var htmlstr = "";
        function print(val){
            htmlstr += val;
        }
        ${template}
        return htmlstr;
    })
    `;
    let fun = eval(codestr);
    return fun(module);
}